package com.hopu.blb_erp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.entity.TIoWarehouse;
import com.hopu.blb_erp.entity.TMenu;
import com.hopu.blb_erp.service.IoWarehouseService;
import com.hopu.blb_erp.service.TIoWarehouseService;
import com.hopu.blb_erp.service.TIomWarehouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@Api
@EnableSwagger2
@RestController
public class TIoWarehouseController {
    @Autowired
    private TIoWarehouseService tIoWarehouseService;
    @ApiOperation("根据仓库名查询")
    @GetMapping("/tIo/{wName}")
    public ResponseEntity<List<TIoWarehouse>> findId(@PathVariable String wName){
        List<TIoWarehouse> tIo = tIoWarehouseService.findTIo(wName);
        return ResponseEntity.ok(tIo);
    }
    @ApiOperation("分页查询出入库信息")
    @GetMapping("/ioWarehouses/{current}/{pageSize}")
    public ResponseEntity<PageEntity> findPage(@PathVariable("current")Integer current, @PathVariable("pageSize")Integer pageSize,
                                               String idNo, String batch){
        PageEntity<TIoWarehouse> page = tIoWarehouseService.findPage(current, pageSize,idNo,batch);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("添加入库信息")
    @PostMapping("/ioWarehouse/{blankCargo}")
    public ResponseEntity<String> add(@RequestBody TIoWarehouse tIoWarehouse,@PathVariable("blankCargo") String blankCargo){
        //判断是否是入库
        if (tIoWarehouse.getIoFlag() == 1){
            tIoWarehouseService.addInIoWarehouse(tIoWarehouse,blankCargo);
        }
        return ResponseEntity.ok("ok");
    }
    @ApiOperation("添加出库信息")
    @PostMapping("/ioWarehouse")
    public ResponseEntity<String> add(@RequestBody TIoWarehouse tIoWarehouse){
        //出库11
        tIoWarehouseService.addOutIoWarehouse(tIoWarehouse);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("删除出入库信息")
    @DeleteMapping("/ioWarehouse/{id}")
    public ResponseEntity<String> delete(@PathVariable("id") Long id){
        tIoWarehouseService.removeById(id);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("更新出入库信息")
    @PutMapping("/ioWarehouse")
    public ResponseEntity<String> modify(@RequestBody TIoWarehouse tIoWarehouse){
        tIoWarehouseService.updateById(tIoWarehouse);
        return ResponseEntity.ok("ok");
    }
}
